package simple.charlie.hibernate.controllers;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import simple.charlie.hibernate.student.entities.Student;

@RestController
@Transactional("studentTransactionManager")
public class StudentController {
	@Autowired
	private SessionFactory sessionFactory;

	@RequestMapping(value = "/student", method = RequestMethod.GET)
	public void student(){
		System.out.println("StudentController.sessionFactory: "+sessionFactory);
		Student student = new Student();
		student.setName("charlie");
		sessionFactory.getCurrentSession().persist(student);
	}
}
